home *** CD-ROM | disk | FTP | other *** search
/ Champak Vol K-12 / Vol K-12.iso / interfac / it.dig / scripts / FSelectableListSymbol.as < prev    next >
Text File  |  2012-08-27  |  11KB  |  361 lines

  1. function FSelectableListClass()
  2. {
  3.    this.init();
  4. }
  5. FSelectableListClass.prototype = new FUIComponentClass();
  6. FSelectableListClass.prototype.init = function()
  7. {
  8.    super.init();
  9.    this.enable = true;
  10.    this.selected = new Array();
  11.    this.topDisplayed = this.numDisplayed = 0;
  12.    this.lastSelected = 0;
  13.    this.tabChildren = false;
  14.    if(this._name != undefined)
  15.    {
  16.       this.dataProvider = new DataProviderClass();
  17.       this.dataProvider.addView(this);
  18.    }
  19. };
  20. FSelectableListClass.prototype.addItemAt = function(index, label, data)
  21. {
  22.    if(index < 0 || !this.enable)
  23.    {
  24.       return undefined;
  25.    }
  26.    this.dataProvider.addItemAt(index,{label:label,data:data});
  27. };
  28. FSelectableListClass.prototype.addItem = function(label, data)
  29. {
  30.    if(!this.enable)
  31.    {
  32.       return undefined;
  33.    }
  34.    this.dataProvider.addItem({label:label,data:data});
  35. };
  36. FSelectableListClass.prototype.removeItemAt = function(index)
  37. {
  38.    this.selectHolder = this.getSelectedIndex();
  39.    var _loc2_ = this.getItemAt(index);
  40.    this.dataProvider.removeItemAt(index);
  41.    return _loc2_;
  42. };
  43. FSelectableListClass.prototype.removeAll = function()
  44. {
  45.    this.dataProvider.removeAll();
  46. };
  47. FSelectableListClass.prototype.replaceItemAt = function(index, newLabel, newData)
  48. {
  49.    this.dataProvider.replaceItemAt(index,{label:newLabel,data:newData});
  50. };
  51. FSelectableListClass.prototype.sortItemsBy = function(fieldName, order)
  52. {
  53.    this.lastSelID = this.dataProvider.getItemID(this.lastSelected);
  54.    this.dataProvider.sortItemsBy(fieldName,order);
  55. };
  56. FSelectableListClass.prototype.getLength = function()
  57. {
  58.    return this.dataProvider.getLength();
  59. };
  60. FSelectableListClass.prototype.getSelectedIndex = function()
  61. {
  62.    for(var _loc3_ in this.selected)
  63.    {
  64.       var _loc2_ = this.selected[_loc3_].sIndex;
  65.       if(_loc2_ != undefined)
  66.       {
  67.          return _loc2_;
  68.       }
  69.    }
  70. };
  71. FSelectableListClass.prototype.getSelectedItem = function()
  72. {
  73.    return this.getItemAt(this.getSelectedIndex());
  74. };
  75. FSelectableListClass.prototype.getItemAt = function(index)
  76. {
  77.    return this.dataProvider.getItemAt(index);
  78. };
  79. FSelectableListClass.prototype.getEnabled = function()
  80. {
  81.    return this.enable;
  82. };
  83. FSelectableListClass.prototype.getValue = function()
  84. {
  85.    var _loc2_ = this.getSelectedItem();
  86.    return _loc2_.data != undefined ? _loc2_.data : _loc2_.label;
  87. };
  88. FSelectableListClass.prototype.setSelectedIndex = function(index, flag)
  89. {
  90.    if(index >= 0 && index < this.getLength() && this.enable)
  91.    {
  92.       this.clearSelected();
  93.       this.selectItem(index,true);
  94.       this.lastSelected = index;
  95.       this.invalidate("updateControl");
  96.       if(flag != false)
  97.       {
  98.          this.executeCallBack();
  99.       }
  100.    }
  101. };
  102. FSelectableListClass.prototype.setDataProvider = function(obj)
  103. {
  104.    this.setScrollPosition(0);
  105.    this.clearSelected();
  106.    if(obj instanceof Array)
  107.    {
  108.       this.dataProvider = new DataProviderClass();
  109.       var _loc2_ = 0;
  110.       while(_loc2_ < obj.length)
  111.       {
  112.          var _loc4_ = typeof obj[_loc2_] != "string" ? obj[_loc2_] : {label:obj[_loc2_]};
  113.          this.dataProvider.addItem(_loc4_);
  114.          _loc2_ = _loc2_ + 1;
  115.       }
  116.    }
  117.    else
  118.    {
  119.       this.dataProvider = obj;
  120.    }
  121.    this.dataProvider.addView(this);
  122. };
  123. FSelectableListClass.prototype.setItemSymbol = function(linkID)
  124. {
  125.    this.tmpPos = this.getScrollPosition();
  126.    this.itemSymbol = linkID;
  127.    this.invalidate("setSize");
  128.    this.setScrollPosition(this.tmpPos);
  129. };
  130. FSelectableListClass.prototype.setEnabled = function(enabledFlag)
  131. {
  132.    this.cleanUI();
  133.    super.setEnabled(enabledFlag);
  134.    this.enable = enabledFlag;
  135.    this.boundingBox_mc.gotoAndStop(!this.enable ? "disabled" : "enabled");
  136.    var _loc4_ = Math.min(this.numDisplayed,this.getLength());
  137.    var _loc3_ = 0;
  138.    while(_loc3_ < _loc4_)
  139.    {
  140.       this.container_mc["fListItem" + _loc3_ + "_mc"].setEnabled(this.enable);
  141.       _loc3_ = _loc3_ + 1;
  142.    }
  143.    if(this.enable)
  144.    {
  145.       this.invalidate("updateControl");
  146.    }
  147. };
  148. FSelectableListClass.prototype.updateControl = function()
  149. {
  150.    var _loc2_ = 0;
  151.    while(_loc2_ < this.numDisplayed)
  152.    {
  153.       this.container_mc["fListItem" + _loc2_ + "_mc"].drawItem(this.getItemAt(this.topDisplayed + _loc2_),this.isSelected(this.topDisplayed + _loc2_));
  154.       _loc2_ = _loc2_ + 1;
  155.    }
  156. };
  157. FSelectableListClass.prototype.setSize = function(w, h)
  158. {
  159.    super.setSize(w,h);
  160.    this.boundingBox_mc._xscale = this.boundingBox_mc._yscale = 100;
  161.    this.boundingBox_mc._xscale = this.width * 100 / this.boundingBox_mc._width;
  162.    this.boundingBox_mc._yscale = this.height * 100 / this.boundingBox_mc._height;
  163.    var _loc3_ = 0;
  164.    while(_loc3_ < this.numDisplayed)
  165.    {
  166.       this.container_mc.attachMovie(this.itemSymbol,"fListItem" + _loc3_ + "_mc",10 + _loc3_,{controller:this,itemNum:_loc3_});
  167.       var _loc4_ = this.container_mc["fListItem" + _loc3_ + "_mc"];
  168.       var _loc5_ = this.scrollOffset != undefined ? this.scrollOffset : 0;
  169.       _loc4_.setSize(this.width - _loc5_,this.itmHgt);
  170.       _loc4_._y = (this.itmHgt - 2) * _loc3_;
  171.       _loc3_ = _loc3_ + 1;
  172.    }
  173.    this.updateControl();
  174. };
  175. FSelectableListClass.prototype.modelChanged = function(eventObj)
  176. {
  177.    var _loc4_ = eventObj.firstRow;
  178.    var _loc6_ = eventObj.lastRow;
  179.    var _loc8_ = eventObj.event;
  180.    if(_loc8_ == "addRows")
  181.    {
  182.       for(var _loc2_ in this.selected)
  183.       {
  184.          if(this.selected[_loc2_].sIndex != undefined && this.selected[_loc2_].sIndex >= _loc4_)
  185.          {
  186.             this.selected[_loc2_].sIndex += _loc6_ - _loc4_ + 1;
  187.             this.setSelectedIndex(this.selected[_loc2_].sIndex,false);
  188.          }
  189.       }
  190.    }
  191.    else if(_loc8_ == "deleteRows")
  192.    {
  193.       if(_loc4_ == _loc6_)
  194.       {
  195.          var _loc5_ = _loc4_;
  196.          if(this.selectHolder == _loc5_)
  197.          {
  198.             this.selectionDeleted = true;
  199.          }
  200.          if(this.topDisplayed + this.numDisplayed >= this.getLength() && this.topDisplayed > 0)
  201.          {
  202.             this.topDisplayed = this.topDisplayed - 1;
  203.             if(this.selectionDeleted && _loc5_ - 1 >= 0)
  204.             {
  205.                this.setSelectedIndex(_loc5_ - 1,false);
  206.             }
  207.          }
  208.          else if(this.selectionDeleted)
  209.          {
  210.             var _loc7_ = this.getLength();
  211.             if(_loc5_ == _loc7_ - 1 && _loc7_ > 1 || _loc5_ > _loc7_ / 2)
  212.             {
  213.                this.setSelectedIndex(_loc5_ - 1,false);
  214.             }
  215.             else
  216.             {
  217.                this.setSelectedIndex(_loc5_,false);
  218.             }
  219.          }
  220.          for(_loc2_ in this.selected)
  221.          {
  222.             if(this.selected[_loc2_].sIndex > _loc4_)
  223.             {
  224.                this.selected[_loc2_].sIndex--;
  225.             }
  226.          }
  227.       }
  228.       else
  229.       {
  230.          this.clearSelected();
  231.          this.topDisplayed = 0;
  232.       }
  233.    }
  234.    else if(_loc8_ == "sort")
  235.    {
  236.       _loc7_ = this.getLength();
  237.       _loc2_ = 0;
  238.       while(_loc2_ < _loc7_)
  239.       {
  240.          if(this.isSelected(_loc2_))
  241.          {
  242.             var _loc3_ = this.dataProvider.getItemID(_loc2_);
  243.             if(_loc3_ == this.lastSelID)
  244.             {
  245.                this.lastSelected = _loc2_;
  246.             }
  247.             this.selected[String(_loc3_)].sIndex = _loc2_;
  248.          }
  249.          _loc2_ = _loc2_ + 1;
  250.       }
  251.    }
  252.    this.invalidate("updateControl");
  253. };
  254. FSelectableListClass.prototype.measureItmHgt = function()
  255. {
  256.    this.attachMovie(this.itemSymbol,"tmpItem_mc",0,{controller:this});
  257.    this.tmpItem_mc.drawItem({label:"Sizer: PjtTopg"},false);
  258.    this.itmHgt = this.tmpItem_mc._height;
  259.    this.tmpItem_mc.removeMovieClip();
  260. };
  261. FSelectableListClass.prototype.selectItem = function(index, selectedFlag)
  262. {
  263.    if(selectedFlag && !this.isSelected(index))
  264.    {
  265.       this.selected[String(this.dataProvider.getItemID(index))] = {sIndex:index};
  266.    }
  267.    else if(!selectedFlag)
  268.    {
  269.       delete this.selected[String(this.dataProvider.getItemID(index))];
  270.    }
  271. };
  272. FSelectableListClass.prototype.isSelected = function(index)
  273. {
  274.    return this.selected[String(this.dataProvider.getItemID(index))].sIndex != undefined;
  275. };
  276. FSelectableListClass.prototype.clearSelected = function()
  277. {
  278.    for(var _loc3_ in this.selected)
  279.    {
  280.       var _loc2_ = this.selected[_loc3_].sIndex;
  281.       if(_loc2_ != undefined && this.topDisplayed <= _loc2_ && _loc2_ < this.topDisplayed + this.numDisplayed)
  282.       {
  283.          this.container_mc["fListItem" + (_loc2_ - this.topDisplayed) + "_mc"].drawItem(this.getItemAt(_loc2_),false);
  284.       }
  285.    }
  286.    delete this.selected;
  287.    this.selected = new Array();
  288. };
  289. FSelectableListClass.prototype.selectionHandler = function(itemNum)
  290. {
  291.    var _loc2_ = this.topDisplayed + itemNum;
  292.    if(this.getItemAt(_loc2_ == undefined))
  293.    {
  294.       this.changeFlag = false;
  295.       return undefined;
  296.    }
  297.    this.changeFlag = true;
  298.    this.clearSelected();
  299.    this.selectItem(_loc2_,true);
  300.    this.container_mc["fListItem" + itemNum + "_mc"].drawItem(this.getItemAt(_loc2_),this.isSelected(_loc2_));
  301. };
  302. FSelectableListClass.prototype.moveSelBy = function(incr)
  303. {
  304.    var _loc3_ = this.getSelectedIndex();
  305.    var _loc2_ = _loc3_ + incr;
  306.    _loc2_ = Math.max(0,_loc2_);
  307.    _loc2_ = Math.min(this.getLength() - 1,_loc2_);
  308.    if(_loc2_ == _loc3_)
  309.    {
  310.       return undefined;
  311.    }
  312.    if(_loc3_ < this.topDisplayed || _loc3_ >= this.topDisplayed + this.numDisplayed)
  313.    {
  314.       this.setScrollPosition(_loc3_);
  315.    }
  316.    if(_loc2_ >= this.topDisplayed + this.numDisplayed || _loc2_ < this.topDisplayed)
  317.    {
  318.       this.setScrollPosition(this.topDisplayed + incr);
  319.    }
  320.    this.selectionHandler(_loc2_ - this.topDisplayed);
  321. };
  322. FSelectableListClass.prototype.clickHandler = function(itmNum)
  323. {
  324.    this.focusRect.removeMovieClip();
  325.    if(!this.focused)
  326.    {
  327.       this.pressFocus();
  328.    }
  329.    this.selectionHandler(itmNum);
  330.    this.onMouseUp = this.releaseHandler;
  331. };
  332. FSelectableListClass.prototype.releaseHandler = function()
  333. {
  334.    if(this.changeFlag)
  335.    {
  336.       this.executeCallBack();
  337.    }
  338.    this.changeFlag = false;
  339.    this.onMouseUp = undefined;
  340. };
  341. FSelectableListClass.prototype.myOnSetFocus = function()
  342. {
  343.    super.myOnSetFocus();
  344.    var _loc3_ = 0;
  345.    while(_loc3_ < this.numDisplayed)
  346.    {
  347.       this.container_mc["fListItem" + _loc3_ + "_mc"].highlight_mc.gotoAndStop("enabled");
  348.       _loc3_ = _loc3_ + 1;
  349.    }
  350. };
  351. FSelectableListClass.prototype.myOnKillFocus = function()
  352. {
  353.    super.myOnKillFocus();
  354.    var _loc3_ = 0;
  355.    while(_loc3_ < this.numDisplayed)
  356.    {
  357.       this.container_mc["fListItem" + _loc3_ + "_mc"].highlight_mc.gotoAndStop("unfocused");
  358.       _loc3_ = _loc3_ + 1;
  359.    }
  360. };
  361.